/********************************************************************************
*Function：errCode_t screen(char ch,const char *sstr)
*Description：led显示器参数控制函数
*Input：char ch,char *sstr
*Output：
*Return：errCode_t枚举类型
********************************************************************************/

#include"screen.h"

errCode_t screen(char ch,const char *sstr)
{
	int fd, res;
	int status = 0;

	//打开屏幕显示设备
	fd = open("/dev/screen", O_RDWR);
	if (fd < 0)
	{
		perror("open device.");
		return OPEN_DEV_FAILURE;
	}

	//读写设备操作
	switch (ch)
	{
	case 'w'://写设备状态
		status = atoi(sstr);
		res = write(fd, &status, 1);
		if (ret < 0)
		{
			perror("set led.");
			return WRITE_ERR;
		}
		else
		{
			printf("set led-->:[%x] -->OK.\n", status);
		}
		break;
	case 'r'://读设备状态
		res = read(fd, &status, 1);
		if (ret < 0)
		{
			perror("read led.");
			return READ_ERR;
		}
		else
		{
			printf("led status is:-->[%x] -->OK.\n", status);
		}
		break;
	default:
		res = ioctl(fd, ch, atoi(sstr));//向驱动写数据
		break;
	}

	close(fd);

	return EXIT_SUC;
}



